package jp.co.hcs.attendancemanagement.data.factory;

import java.io.Reader;
import java.sql.SQLException;

import jp.co.hcs.attendancemanagement.AMLogger;
import jp.co.hcs.attendancemanagement.data.dao.ApprovalCompanyDAO;
import jp.co.hcs.attendancemanagement.data.dao.ApprovalDAO;
import jp.co.hcs.attendancemanagement.data.dao.ApprovalDepartmentDAO;
import jp.co.hcs.attendancemanagement.data.dao.ApprovalDivisionDAO;
import jp.co.hcs.attendancemanagement.data.dao.ApprovalEmployeeDAO;
import jp.co.hcs.attendancemanagement.data.dao.ApprovalGroupHeaderDAO;
import jp.co.hcs.attendancemanagement.data.dao.AuthenticationDAO;
import jp.co.hcs.attendancemanagement.data.dao.CompanyDAO;
import jp.co.hcs.attendancemanagement.data.dao.DepartmentDAO;
import jp.co.hcs.attendancemanagement.data.dao.DepartmentMasterDAO;
import jp.co.hcs.attendancemanagement.data.dao.DivisionDAO;
import jp.co.hcs.attendancemanagement.data.dao.EffortActualDAO;
import jp.co.hcs.attendancemanagement.data.dao.EmployeeMasterDAO;
import jp.co.hcs.attendancemanagement.data.dao.EmployeeVacationDAO;
import jp.co.hcs.attendancemanagement.data.dao.HolidayDAO;
import jp.co.hcs.attendancemanagement.data.dao.JobDAO;
import jp.co.hcs.attendancemanagement.data.dao.LeaveApproveDAO;
import jp.co.hcs.attendancemanagement.data.dao.PerformanceStampDAO;
import jp.co.hcs.attendancemanagement.data.dao.PositionMasterDAO;
import jp.co.hcs.attendancemanagement.data.dao.ProjectDAO;
import jp.co.hcs.attendancemanagement.data.dao.RestTimeActualDAO;
import jp.co.hcs.attendancemanagement.data.dao.RestTimeDAO;
import jp.co.hcs.attendancemanagement.data.dao.SubstituteHolidayActualDAO;
import jp.co.hcs.attendancemanagement.data.dao.WorkDAO;
import jp.co.hcs.attendancemanagement.data.dao.WorkMessageDAO;
import jp.co.hcs.attendancemanagement.data.dao.WorkingDayApproveDAO;
import jp.co.hcs.attendancemanagement.data.dao.WorkingMonthApproveDAO;
import jp.co.hcs.attendancemanagement.data.dao.WorkingTimeActualDAO;
import jp.co.hcs.attendancemanagement.data.dao.WorkingTimeMasterDAO;
import jp.co.hcs.attendancemanagement.data.dao.WorkingTimeQuotaDAO;
import jp.co.hcs.attendancemanagement.data.dao.impl.ApprovalCompanyDAOImpl;
import jp.co.hcs.attendancemanagement.data.dao.impl.ApprovalDAOImpl;
import jp.co.hcs.attendancemanagement.data.dao.impl.ApprovalDepartmentDAOImpl;
import jp.co.hcs.attendancemanagement.data.dao.impl.ApprovalDivisionDAOImpl;
import jp.co.hcs.attendancemanagement.data.dao.impl.ApprovalEmployeeDAOImpl;
import jp.co.hcs.attendancemanagement.data.dao.impl.ApprovalGroupHeaderDAOImpl;
import jp.co.hcs.attendancemanagement.data.dao.impl.AuthenticationDAOImpl;
import jp.co.hcs.attendancemanagement.data.dao.impl.CompanyDAOImpl;
import jp.co.hcs.attendancemanagement.data.dao.impl.DepartmentDAOImpl;
import jp.co.hcs.attendancemanagement.data.dao.impl.DepartmentMasterDAOImpl;
import jp.co.hcs.attendancemanagement.data.dao.impl.DivisionDAOImpl;
import jp.co.hcs.attendancemanagement.data.dao.impl.EffortActualDAOImpl;
import jp.co.hcs.attendancemanagement.data.dao.impl.EmployeeMasterDAOImpl;
import jp.co.hcs.attendancemanagement.data.dao.impl.EmployeeVacationDAOImpl;
import jp.co.hcs.attendancemanagement.data.dao.impl.HolidayDAOImpl;
import jp.co.hcs.attendancemanagement.data.dao.impl.JobDAOImpl;
import jp.co.hcs.attendancemanagement.data.dao.impl.LeaveApproveDAOImpl;
import jp.co.hcs.attendancemanagement.data.dao.impl.PerformanceStampDAOImpl;
import jp.co.hcs.attendancemanagement.data.dao.impl.PositionMasterDAOImpl;
import jp.co.hcs.attendancemanagement.data.dao.impl.ProjectDAOImpl;
import jp.co.hcs.attendancemanagement.data.dao.impl.RestTimeActualDAOImpl;
import jp.co.hcs.attendancemanagement.data.dao.impl.RestTimeDAOImpl;
import jp.co.hcs.attendancemanagement.data.dao.impl.SubstituteHolidayActualDAOImpl;
import jp.co.hcs.attendancemanagement.data.dao.impl.WorkDAOImpl;
import jp.co.hcs.attendancemanagement.data.dao.impl.WorkMessageDAOImpl;
import jp.co.hcs.attendancemanagement.data.dao.impl.WorkingDayApproveDAOImpl;
import jp.co.hcs.attendancemanagement.data.dao.impl.WorkingMonthApproveDAOImpl;
import jp.co.hcs.attendancemanagement.data.dao.impl.WorkingTimeActualDAOImpl;
import jp.co.hcs.attendancemanagement.data.dao.impl.WorkingTimeMasterDAOImpl;
import jp.co.hcs.attendancemanagement.data.dao.impl.WorkingTimeQuotaDAOImpl;

import org.apache.log4j.Logger;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

/**
 * A factory for creating AMDao objects.
 */
public class AMDaoFactory implements DaoFactory {
	
  private static Logger log = AMLogger.getLogger(AMDaoFactory.class.getName());

  private static final SqlMapClient sqlMapClient;
	
  /** The a mdao factory instace. */
  private static DaoFactory aMDAOFactoryInstace = new AMDaoFactory();

  /**
   * Gets the single instance of AMDaoFactory.
   * 
   * @return single instance of AMDaoFactory
   */
  public static DaoFactory getInstance() {
    return aMDAOFactoryInstace;
  }

  /** The approval company dao. */
  private static ApprovalCompanyDAO approvalCompanyDAO = null;

  /** The approval dao. */
  private static ApprovalDAO approvalDAO = null;

  /** The approval department dao. */
  private static ApprovalDepartmentDAO approvalDepartmentDAO = null;

  /** The approval division dao. */
  private static ApprovalDivisionDAO approvalDivisionDAO = null;

  /** The approval employee dao. */
  private static ApprovalEmployeeDAO approvalEmployeeDAO = null;

  /** The approval group header dao. */
  private static ApprovalGroupHeaderDAO approvalGroupHeaderDAO = null;

  /** The authentication dao. */
  private static AuthenticationDAO authenticationDAO = null;

  /** The company dao. */
  private static CompanyDAO companyDAO = null;

  /** The department dao. */
  private static DepartmentDAO departmentDAO = null;

  /** The department master dao. */
  private static DepartmentMasterDAO departmentMasterDAO = null;

  /** The division dao. */
  private static DivisionDAO divisionDAO = null;

  /** The effort actual dao. */
  private static EffortActualDAO effortActualDAO = null;

  /** The employee master dao. */
  private static EmployeeMasterDAO employeeMasterDAO = null;

  /** The employee vacation dao. */
  private static EmployeeVacationDAO employeeVacationDAO = null;

  /** The holiday dao. */
  private static HolidayDAO holidayDAO = null;

  /** The job dao. */
  private static JobDAO jobDAO = null;

  /** The leave approve dao. */
  private static LeaveApproveDAO leaveApproveDAO = null;

  /** The performance stamp dao. */
  private static PerformanceStampDAO performanceStampDAO = null;

  /** The position master dao. */
  private static PositionMasterDAO positionMasterDAO = null;

  /** The project dao. */
  private static ProjectDAO projectDAO = null;

  /** The rest time actual dao. */
  private static RestTimeActualDAO restTimeActualDAO = null;

  /** The rest time dao. */
  private static RestTimeDAO restTimeDAO = null;

  /** The substitute holiday actual dao. */
  private static SubstituteHolidayActualDAO substituteHolidayActualDAO = null;

  /** The work dao. */
  private static WorkDAO workDAO = null;

  /** The working day approve dao. */
  private static WorkingDayApproveDAO workingDayApproveDAO = null;

  /** The working month approve dao. */
  private static WorkingMonthApproveDAO workingMonthApproveDAO = null;

  /** The working time actual dao. */
  private static WorkingTimeActualDAO workingTimeActualDAO = null;

  /** The working time master dao. */
  private static WorkingTimeMasterDAO workingTimeMasterDAO = null;

  /** The working time quota dao. */
  private static WorkingTimeQuotaDAO workingTimeQuotaDAO = null;

  /** The work message dao. */
  private static WorkMessageDAO workMessageDAO = null;

  /*
   * (non-Javadoc)
   * 
   * @see jp.co.hcs.attendancemanagement.data.factory.DaoFactory#getApprovalCompanyDAO ()
   */
  public ApprovalCompanyDAO getApprovalCompanyDAO() {
    return approvalCompanyDAO;
  }

  /*
   * (non-Javadoc)
   * 
   * @see jp.co.hcs.attendancemanagement.data.factory.DaoFactory#getApprovalDAO()
   */
  public ApprovalDAO getApprovalDAO() {
    return approvalDAO;
  }

  /*
   * (non-Javadoc)
   * 
   * @see jp.co.hcs.attendancemanagement.data.factory.DaoFactory#getApprovalDepartmentDAO ()
   */
  public ApprovalDepartmentDAO getApprovalDepartmentDAO() {
    return approvalDepartmentDAO;
  }

  /*
   * (non-Javadoc)
   * 
   * @see jp.co.hcs.attendancemanagement.data.factory.DaoFactory#getApprovalDivisionDAO ()
   */
  public ApprovalDivisionDAO getApprovalDivisionDAO() {
    return approvalDivisionDAO;
  }

  /*
   * (non-Javadoc)
   * 
   * @see jp.co.hcs.attendancemanagement.data.factory.DaoFactory#getApprovalEmployeeDAO ()
   */
  public ApprovalEmployeeDAO getApprovalEmployeeDAO() {
    return approvalEmployeeDAO;
  }

  /*
   * (non-Javadoc)
   * 
   * @see jp.co.hcs.attendancemanagement.data.factory.DaoFactory# getApprovalGroupHeaderDAO()
   */
  public ApprovalGroupHeaderDAO getApprovalGroupHeaderDAO() {
    return approvalGroupHeaderDAO;
  }

  /*
   * (non-Javadoc)
   * 
   * @see jp.co.hcs.attendancemanagement.data.factory.DaoFactory#getAuthenticationDAO ()
   */
  public AuthenticationDAO getAuthenticationDAO() {
    return authenticationDAO;
  }

  /*
   * (non-Javadoc)
   * 
   * @see jp.co.hcs.attendancemanagement.data.factory.DaoFactory#getCompanyDAO()
   */
  public CompanyDAO getCompanyDAO() {
    return companyDAO;
  }

  /*
   * (non-Javadoc)
   * 
   * @see jp.co.hcs.attendancemanagement.data.factory.DaoFactory#getDepartmentDAO()
   */
  public DepartmentDAO getDepartmentDAO() {
    return departmentDAO;
  }

  /*
   * (non-Javadoc)
   * 
   * @see jp.co.hcs.attendancemanagement.data.factory.DaoFactory#getDepartmentMasterDAO ()
   */
  public DepartmentMasterDAO getDepartmentMasterDAO() {
    return departmentMasterDAO;
  }

  /*
   * (non-Javadoc)
   * 
   * @see jp.co.hcs.attendancemanagement.data.factory.DaoFactory#getDivisionDAO()
   */
  public DivisionDAO getDivisionDAO() {
    return divisionDAO;
  }

  /*
   * (non-Javadoc)
   * 
   * @see jp.co.hcs.attendancemanagement.data.factory.DaoFactory#getEffortActualDAO()
   */
  public EffortActualDAO getEffortActualDAO() {
    return effortActualDAO;
  }

  /*
   * (non-Javadoc)
   * 
   * @see jp.co.hcs.attendancemanagement.data.factory.DaoFactory#getEmployeeMasterDAO ()
   */
  public EmployeeMasterDAO getEmployeeMasterDAO() {
    return employeeMasterDAO;
  }

  /*
   * (non-Javadoc)
   * 
   * @see jp.co.hcs.attendancemanagement.data.factory.DaoFactory#getEmployeeVacationDAO ()
   */
  public EmployeeVacationDAO getEmployeeVacationDAO() {
    return employeeVacationDAO;
  }

  /*
   * (non-Javadoc)
   * 
   * @see jp.co.hcs.attendancemanagement.data.factory.DaoFactory#getHolidayDAO()
   */
  public HolidayDAO getHolidayDAO() {
    return holidayDAO;
  }

  /*
   * (non-Javadoc)
   * 
   * @see jp.co.hcs.attendancemanagement.data.factory.DaoFactory#getJobDivisionDAO()
   */
  public JobDAO getJobDivisionDAO() {
    return jobDAO;
  }

  /*
   * (non-Javadoc)
   * 
   * @see jp.co.hcs.attendancemanagement.data.factory.DaoFactory#getLeaveApproveDAO()
   */
  public LeaveApproveDAO getLeaveApproveDAO() {
    return leaveApproveDAO;
  }

  /*
   * (non-Javadoc)
   * 
   * @see jp.co.hcs.attendancemanagement.data.factory.DaoFactory#getPerformanceStampDAO ()
   */
  public PerformanceStampDAO getPerformanceStampDAO() {
    return performanceStampDAO;
  }

  /*
   * (non-Javadoc)
   * 
   * @see jp.co.hcs.attendancemanagement.data.factory.DaoFactory#getPositionMasterDAO ()
   */
  public PositionMasterDAO getPositionMasterDAO() {
    return positionMasterDAO;
  }

  /*
   * (non-Javadoc)
   * 
   * @see jp.co.hcs.attendancemanagement.data.factory.DaoFactory#getProjectDAO()
   */
  public ProjectDAO getProjectDAO() {
    return projectDAO;
  }

  /*
   * (non-Javadoc)
   * 
   * @see jp.co.hcs.attendancemanagement.data.factory.DaoFactory#getRestTimeActualDAO ()
   */
  public RestTimeActualDAO getRestTimeActualDAO() {
    return restTimeActualDAO;
  }

  /*
   * (non-Javadoc)
   * 
   * @see jp.co.hcs.attendancemanagement.data.factory.DaoFactory#getRestTimeDAO()
   */
  public RestTimeDAO getRestTimeDAO() {
    return restTimeDAO;
  }

  /*
   * (non-Javadoc)
   * 
   * @see jp.co.hcs.attendancemanagement.data.factory.DaoFactory# getSubstituteHolidayActualDAO()
   */
  public SubstituteHolidayActualDAO getSubstituteHolidayActualDAO() {
    return substituteHolidayActualDAO;
  }

  /*
   * (non-Javadoc)
   * 
   * @see jp.co.hcs.attendancemanagement.data.factory.DaoFactory#getWorkDAO()
   */
  public WorkDAO getWorkDAO() {
    return workDAO;
  }

  /*
   * (non-Javadoc)
   * 
   * @see jp.co.hcs.attendancemanagement.data.factory.DaoFactory#getWorkingDayApproveDAO ()
   */
  public WorkingDayApproveDAO getWorkingDayApproveDAO() {
    return workingDayApproveDAO;
  }

  /*
   * (non-Javadoc)
   * 
   * @see jp.co.hcs.attendancemanagement.data.factory.DaoFactory# getWorkingMonthApproveDAO()
   */
  public WorkingMonthApproveDAO getWorkingMonthApproveDAO() {
    return workingMonthApproveDAO;
  }

  /*
   * (non-Javadoc)
   * 
   * @see jp.co.hcs.attendancemanagement.data.factory.DaoFactory#getWorkingTimeActualDAO ()
   */
  public WorkingTimeActualDAO getWorkingTimeActualDAO() {
    return workingTimeActualDAO;
  }

  /*
   * (non-Javadoc)
   * 
   * @see jp.co.hcs.attendancemanagement.data.factory.DaoFactory#getWorkingTimeMasterDAO ()
   */
  public WorkingTimeMasterDAO getWorkingTimeMasterDAO() {
    return workingTimeMasterDAO;
  }

  /*
   * (non-Javadoc)
   * 
   * @see jp.co.hcs.attendancemanagement.data.factory.DaoFactory#getWorkingTimeQuotaDAO ()
   */
  public WorkingTimeQuotaDAO getWorkingTimeQuotaDAO() {
    return workingTimeQuotaDAO;
  }

  /*
   * (non-Javadoc)
   * 
   * @see jp.co.hcs.attendancemanagement.data.factory.DaoFactory#getWorkMessageDAO()
   */
  public WorkMessageDAO getWorkMessageDAO() {
    return workMessageDAO;
  }

  static {
  try {
		log.debug("Attempting to initialize SqlMap");
		String resource = "SqlMapConfig.xml";
		Reader reader = Resources.getResourceAsReader(resource);
		sqlMapClient = SqlMapClientBuilder.buildSqlMapClient(reader);
		log.debug("Initialized SqlMap");
	} catch (Exception e) {
		log.error("Error intializing BaseIbatisDao ", e);
		e.printStackTrace();
		throw new RuntimeException(
				"Error initializing BaseIbatisDao class. Cause: " + e);
	}
	
    approvalCompanyDAO = new ApprovalCompanyDAOImpl();
    approvalCompanyDAO.setSqlMapClient(sqlMapClient);
    approvalDAO = new ApprovalDAOImpl();
    approvalDAO.setSqlMapClient(sqlMapClient);
    approvalDepartmentDAO = new ApprovalDepartmentDAOImpl();
    approvalDepartmentDAO.setSqlMapClient(sqlMapClient);
    approvalDivisionDAO = new ApprovalDivisionDAOImpl();
    approvalDivisionDAO.setSqlMapClient(sqlMapClient);
    approvalEmployeeDAO = new ApprovalEmployeeDAOImpl();
    approvalEmployeeDAO.setSqlMapClient(sqlMapClient);
    approvalGroupHeaderDAO = new ApprovalGroupHeaderDAOImpl();
    approvalGroupHeaderDAO.setSqlMapClient(sqlMapClient);
    authenticationDAO = new AuthenticationDAOImpl();
    authenticationDAO.setSqlMapClient(sqlMapClient);
    companyDAO = new CompanyDAOImpl();
    companyDAO.setSqlMapClient(sqlMapClient);
    departmentDAO = new DepartmentDAOImpl();
    departmentDAO.setSqlMapClient(sqlMapClient);
    departmentMasterDAO = new DepartmentMasterDAOImpl();
    departmentMasterDAO.setSqlMapClient(sqlMapClient);
    divisionDAO = new DivisionDAOImpl();
    divisionDAO.setSqlMapClient(sqlMapClient);
    effortActualDAO = new EffortActualDAOImpl();
    effortActualDAO.setSqlMapClient(sqlMapClient);
    employeeMasterDAO = new EmployeeMasterDAOImpl();
    employeeMasterDAO.setSqlMapClient(sqlMapClient);
    employeeVacationDAO = new EmployeeVacationDAOImpl();
    employeeVacationDAO.setSqlMapClient(sqlMapClient);
    holidayDAO = new HolidayDAOImpl();
    holidayDAO.setSqlMapClient(sqlMapClient);
    jobDAO = new JobDAOImpl();
    jobDAO.setSqlMapClient(sqlMapClient);
    leaveApproveDAO = new LeaveApproveDAOImpl();
    leaveApproveDAO.setSqlMapClient(sqlMapClient);
    performanceStampDAO = new PerformanceStampDAOImpl();
    performanceStampDAO.setSqlMapClient(sqlMapClient);
    positionMasterDAO = new PositionMasterDAOImpl();
    positionMasterDAO.setSqlMapClient(sqlMapClient);
    projectDAO = new ProjectDAOImpl();
    projectDAO.setSqlMapClient(sqlMapClient);
    restTimeActualDAO = new RestTimeActualDAOImpl();
    restTimeActualDAO.setSqlMapClient(sqlMapClient);
    restTimeDAO = new RestTimeDAOImpl();
    restTimeDAO.setSqlMapClient(sqlMapClient);
    substituteHolidayActualDAO = new SubstituteHolidayActualDAOImpl();
    substituteHolidayActualDAO.setSqlMapClient(sqlMapClient);
    workDAO = new WorkDAOImpl();
    workDAO.setSqlMapClient(sqlMapClient);
    workingDayApproveDAO = new WorkingDayApproveDAOImpl();
    workingDayApproveDAO.setSqlMapClient(sqlMapClient);
    workingMonthApproveDAO = new WorkingMonthApproveDAOImpl();
    workingMonthApproveDAO.setSqlMapClient(sqlMapClient);
    workingTimeActualDAO = new WorkingTimeActualDAOImpl();
    workingTimeActualDAO.setSqlMapClient(sqlMapClient);
    workingTimeMasterDAO = new WorkingTimeMasterDAOImpl();
    workingTimeMasterDAO.setSqlMapClient(sqlMapClient);
    workingTimeQuotaDAO = new WorkingTimeQuotaDAOImpl();
    workingTimeQuotaDAO.setSqlMapClient(sqlMapClient);
    workMessageDAO = new WorkMessageDAOImpl();
    workMessageDAO.setSqlMapClient(sqlMapClient);
  }

  public void startTransaction() throws SQLException {
    sqlMapClient.startTransaction();
  }

  public void commitTransaction() throws SQLException {
    sqlMapClient.commitTransaction();
  }

  public void endTransaction() throws SQLException {
    sqlMapClient.endTransaction();
  }
}
